#ifndef NODELIST_H
#define NODELIST_H

#include <QList>
#include <QAbstractListModel>

#include "Node.h"

class NodeList : public QAbstractListModel
{
    Q_OBJECT
public:
    NodeList();
    ~NodeList();

    virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
    virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;

    void addNode(const Node & node, int index = -1);
    void addNode(const Node & prevNode, const Node & node);
    void removeNode(const Node & node);

    const QList<Node> & innerList() const { return *list; }

    void setThisNode(Node * thisNode);

    bool isThisNodeFirst();

    const Node & getThisNode() const { return *thisNode; }
    const Node & getPrevNode() const;
    const Node & getNextNode() const;
    const Node & getNode(const QString & nodeId) const;
    const Node & getNode(const QString & address, quint16 port) const;
    Node & getNode(const QString & nodeId);

    void setLockedId(const QString & lockedId);
    const QString & getLockedId() { return lockedId; }
private:
    QList<Node> *list;
    Node *thisNode;
    QString lockedId;
};

#endif // NODELIST_H
